package com.yty.system.test;


public class Ticket implements Runnable{

	//共200张票
	int ticket = 3;

	public void run() {
		while (true) {
			// 抢票业务代码实现
			qiangpiao();

		}
	}

	public synchronized void qiangpiao() {
		try {
			if(ticket > 0){
				Thread.sleep(500);
				// 业务代码实现功能
				System.out.println(Thread.currentThread().getName() + "正在卖票，剩余票数为：" + ticket--);
			}
		}catch (Exception e) {
			e.printStackTrace();

		}

	}
}
